package vy.org.app.page.printlabel.report.instance;

import java.util.Date;

import org.vy.dal.dao.VyPrintLabelReportDAO;
import org.vy.dal.dao.VyPrintLabelReportDO;
import org.vy.dal.dao.VyPrintLabelReportInstanceDAO;
import org.vy.dal.dao.VyPrintLabelReportInstanceDO;

public abstract class ReportInstance implements Runnable {
	
	protected VyPrintLabelReportDO report;
	protected VyPrintLabelReportInstanceDO instance;
	
	protected ReportInstance(Integer reportId) throws Exception {
		report = VyPrintLabelReportDAO.findByReportId(reportId);
		
		VyPrintLabelReportInstanceDO dto = new VyPrintLabelReportInstanceDO();
		dto.setReportInstanceId(0);
		dto.setReportId(reportId);
		dto.setStatus(ReportStatusEnum.NEW.getId());
		dto.setStartTime(new Date());
		instance = VyPrintLabelReportInstanceDAO.insert(dto);
	}
	
	public final void stop(){
		instance.setStatus(ReportStatusEnum.CANCELLED.getId());
	}

	final void remove(){
		ReportManager.getInstance().remove(report.getReportId());
	}

}
